package com.qf;

import org.openjdk.jol.info.ClassLayout;

public class Math1 {
    //静态数据不属于实例对象，存储在元空间中
    public static final int initData = 666;
    public static User user = new User();

    public int i = 10;

    public int compute() {  //一个方法对应一块栈帧内存区域
        int a = 1;
        int b = 2;
        int c = (a + b) * 10;
        return c;
    }

    public static void main(String[] args) {
        Math1 math = new Math1();
        math.compute();

        ClassLayout classLayout = ClassLayout.parseInstance(math);
        System.out.println(classLayout.toPrintable());

        System.out.println("============================");

        A a = new A();
        ClassLayout classLayout1 = ClassLayout.parseInstance(a);
        System.out.println(classLayout1.toPrintable());

    }


    public static class A {
        //8B mark word
        //4B Klass Pointer 如果关闭压缩‐XX:‐UseCompressedClassPointers或‐XX:‐UseCompressedOops，则占用8B
        int id; //4B
        String name; //4B 如果关闭压缩‐XX:‐UseCompressedOops，则占用8B
        byte b; //1B
        Object o; //4B 如果关闭压缩‐XX:‐UseCompressedOops，则占用8B
    }
}